<?php 
/**
 * TomatoCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version 	$Id: add.phtml 4700 2010-08-16 16:14:34Z huuphuoc $
 * @since		2.0.0
 */
?>
<?php 
$this->headTitle($this->translator('category_add_page_title'));

$this->headScript()
	->appendFile($this->APP_STATIC_SERVER . '/js/jquery.validate/jquery.validate.min.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/tomato/util.js');
?>

<div class="grid_12 t_a_ui_breadcrumb">
	<span><a href="<?php echo $this->url(array(), 'category_category_list'); ?>"><?php echo $this->translator('category_list_breadcrumb'); ?></a></span>
	<span><?php echo $this->translator('category_add_breadcrumb'); ?></span>	
</div>

<div class="grid_12"><?php echo $this->flashMessenger(); ?></div>

<form method="post" action="<?php echo $this->url(array(), 'category_category_add'); ?>" id="addCategoryForm">
<div class="grid_12 t_a_bottom"><?php echo $this->translator('category_add_guide'); ?></div>

<div class="grid_12 t_a_bottom">
	<div class="prefix_1 suffix_1">
		<div class="clearfix t_a_bottom">
			<label><?php echo $this->translator('category_name'); ?>:</label>
			<input maxlength="255" type="text" id="name" name="name" style="width: 300px" />
		</div>
		
		<hr />
		
		<div class="clearfix t_a_bottom">
			<label><?php echo $this->translator('category_slug'); ?>:</label>
			<input maxlength="255" type="text" id="slug" name="slug" style="width: 300px" />
		</div>
		
		<hr />
		
		<div class="clearfix t_a_bottom">
			<label><?php echo $this->translator('category_meta'); ?>:</label>
			<textarea id="meta" name="meta" style="width: 300px; height: 100px"></textarea>
		</div>
		
		<hr />
		
		<div class="clearfix t_a_bottom">
			<div class="grid_2 alpha">
				<label><?php echo $this->translator('category_language'); ?>:</label>
			</div>
			<div class="grid_8 omega">
				<?php echo $this->languageSelector(); ?>
			</div>
		</div>
		
		<hr />
		
		<div class="clearfix t_a_bottom">
			<div class="grid_2 alpha">
				<label><?php echo $this->translator('category_source_item'); ?>:</label>
			</div>
			<div class="grid_8 omega">
				<div class="translatable translationSourceItems">
					<?php 
					echo $this->translatableCategory(array(
									'id'       => 'sourceItem',
									'name'     => 'sourceItem',
									'selected' => (null == $this->sourceCategory) ? null : $this->sourceCategory->category_id,
									'disabled' => (null == $this->sourceCategory) ? null : $this->sourceCategory->category_id, 
								), $this->lang);
					?>
				</div>
			</div>
		</div>
		
		<hr />
		
		<div class="clearfix t_a_bottom">
			<div class="grid_2 alpha">
				<label><?php echo $this->translator('category_parent'); ?>:</label>
			</div>
			<div class="grid_8 omega">
				<div class="translatable">
					<?php echo $this->categorySelect(array('id' => 'parentId', 'name' => 'parentId')); ?>
				</div>
			</div>
		</div>
		
		<hr />
		
		<div class="clearfix t_a_bottom">
			<label>&nbsp;</label>
			<button type="submit"><span><?php echo $this->translator('category_add_save_button'); ?></span></button>
		</div>
	</div>
</div>
</form>

<script type="text/javascript">
$(document).ready(function() {
	/**
	 * Validate form
	 */
	$.validator.addMethod('slug', function(value) {
		var regex = new RegExp(/^[a-z0-9\-]+$/);
		if (value.match(regex)) {
			return true;
		} else {
			return false;
		}
	});
	
	$('#addCategoryForm').validate({
		rules: {
			name: {
				required: true,
		  		maxlength: 255
			},
			slug: {
		  		required: true,
		  		slug: true,
		  		maxlength: 255
			}
	    },
	    messages: {
	    	name: {
	        	required: "<?php echo $this->translator('category_name_required'); ?>",
				maxlength: "<?php echo $this->translator('category_name_maxlength'); ?>"
			},
			slug: { 
	        	required: "<?php echo $this->translator('category_slug_required'); ?>",
	        	slug: "<?php echo $this->translator('category_slug_validate'); ?>",
	        	maxlength: "<?php echo $this->translator('category_slug_maxlength'); ?>"
	    	}
		}
	});

	/**
	 * Automatically create slug once user enter the title
	 */
	$('#name').bind('change', function() {
		$('#slug').val(Tomato.Util.generateSlug($(this).val()));
	});
});
</script>
